package com.medicine.manage.service.impl;

import java.util.List;
import com.medicine.common.utils.DateUtils;
import com.medicine.common.utils.SecurityUtils;
import com.medicine.manage.block.service.IBlockProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.medicine.manage.mapper.BoilingMapper;
import com.medicine.manage.domain.Boiling;
import com.medicine.manage.service.IBoilingService;

/**
 * 煎药Service业务层处理
 * 
 * @author admin
 * @date 2024-10-14
 */
@Service
public class BoilingServiceImpl implements IBoilingService 
{
    @Autowired
    private BoilingMapper boilingMapper;

    @Autowired
    @Qualifier("blockProcessBoiling")
    private IBlockProcessService blockProcessBoilingService;

    /**
     * 查询煎药
     * 
     * @param id 煎药主键
     * @return 煎药
     */
    @Override
    public Boiling selectBoilingById(Long id)
    {
        return boilingMapper.selectBoilingById(id);
    }

    /**
     * 查询煎药列表
     * 
     * @param boiling 煎药
     * @return 煎药
     */
    @Override
    public List<Boiling> selectBoilingList(Boiling boiling)
    {
        return boilingMapper.selectBoilingList(boiling);
    }

    /**
     * 新增煎药
     * 
     * @param boiling 煎药
     * @return 结果
     */
    @Override
    public int insertBoiling(Boiling boiling)
    {
        boiling.setCreateBy(SecurityUtils.getLoginUser().getUserId().toString());
        boiling.setCreateTime(DateUtils.getNowDate());
        int result = boilingMapper.insertBoiling(boiling);
        blockProcessBoilingService.insertProcessObj(boiling, SecurityUtils.getLoginUser().getDeptId(), SecurityUtils.getLoginUser().getUserId());
        return result;
    }

    /**
     * 修改煎药
     * 
     * @param boiling 煎药
     * @return 结果
     */
    @Override
    public int updateBoiling(Boiling boiling)
    {
        boiling.setUpdateBy(SecurityUtils.getLoginUser().getUserId().toString());
        boiling.setUpdateTime(DateUtils.getNowDate());

        int result = boilingMapper.updateBoiling(boiling);
        Boiling b = this.selectBoilingById(boiling.getId());
        blockProcessBoilingService.updateProcessObj(b, SecurityUtils.getLoginUser().getDeptId(), SecurityUtils.getLoginUser().getUserId());

        return result;
    }

    /**
     * 批量删除煎药
     * 
     * @param ids 需要删除的煎药主键
     * @return 结果
     */
    @Override
    public int deleteBoilingByIds(Long[] ids)
    {
        return boilingMapper.deleteBoilingByIds(ids);
    }

    /**
     * 删除煎药信息
     * 
     * @param id 煎药主键
     * @return 结果
     */
    @Override
    public int deleteBoilingById(Long id)
    {
        return boilingMapper.deleteBoilingById(id);
    }
}
